package com.wt.struggle.goodbye.wxutil

import android.os.Handler
import com.sina.weibo.sdk.auth.Oauth2AccessToken
import com.sina.weibo.sdk.auth.WbAuthListener
import com.sina.weibo.sdk.auth.WbConnectErrorMessage
import com.sina.weibo.sdk.auth.sso.SsoHandler
import com.xin.lv.yang.utils.info.HttpInfo
import com.xin.lv.yang.utils.utils.HttpUtils


class SinaUtils(val handler: Handler) {

    companion object {
        val SUCCESS = 123
    }

    lateinit var ssoHandler: SsoHandler

    fun login(ssoHandler: SsoHandler) {
        this.ssoHandler = ssoHandler
        ssoHandler.authorize(object : WbAuthListener {
            override fun onSuccess(p0: Oauth2AccessToken?) {
                val accessToken = p0!!.token
                val uid = p0.uid
                getUserInfo(accessToken, uid)

            }

            override fun onFailure(p0: WbConnectErrorMessage?) {

            }

            override fun cancel() {

            }

        })

    }

    private fun getUserInfo(accessToken: String?, uid: String?) {
        val url = "https://api.weibo.com/2/users/show.json"
        val arr: ArrayList<HttpInfo> = arrayListOf()
        arr.add(HttpInfo("access_token", accessToken))
        arr.add(HttpInfo("uid", uid))
        HttpUtils.getInstance().get(url, arr, SUCCESS, handler)


    }
}